package com.lkl.project.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lkl.longapicommon.model.entity.User;
import com.lkl.longapicommon.service.InnerUserService;
import com.lkl.project.common.ErrorCode;
import com.lkl.project.exception.BusinessException;
import com.lkl.project.mapper.UserMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * @author longlong
 * @date 2023-12-22 11:25
 * description
 */
@DubboService
public class InnerUserServiceImpl implements InnerUserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 实现接口中的getInvokeUser方法，用于根据密钥获取内部用户信息
     * @param accessKey
     * @return 内部信息，如果找不到返回null
     * @throws BusinessException 抛出业务异常
     */
    @Override
    public User getInvokeUser(String accessKey) {
        //参数校验
        if (StringUtils.isAnyBlank(accessKey)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        //创建查询条件包装器
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("accessKey",accessKey);

        //使用UserMapper的selectOne方法查询用户信息
        return userMapper.selectOne(queryWrapper);
    }
}
